package Test.FOURTH.Three;

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;

public class SaveFileGUI {
    public static void main(String[] args) throws Exception{
        Frame frame=new Frame("文件");
        WriteProcesser writeProcesser=new WriteProcesser();
        frame.setSize(620,620);
        frame.setLayout(new BorderLayout());
        File file=new File("TESTfILEonEtwo.txt");
        if (file.exists()){
            file.delete();
            file.createNewFile();
        }else {
            file.createNewFile();
        }

        TextField writeArea=new TextField("在这里输入文件内容");
        writeArea.setEditable(true);
        writeArea.addActionListener(writeProcesser);

        frame.add(writeArea);
        frame.validate();
        frame.setVisible(true);
    }
}


class WriteProcesser implements ActionListener {

    @Override
    public void actionPerformed(ActionEvent e) {
        File file=new File("TESTfILEonEtwo.txt");

        try {
            FileWriter fw=new FileWriter(file);
            fw.write(e.getActionCommand());
            fw.flush();
        } catch (IOException e1) {
            e1.printStackTrace();
        }

    }
}
